package chatin.admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UsuarioDAO {

    private Connection connection;

    public UsuarioDAO() {
        this.connection = ConnectionsGuardian.getConnectionsGuardian().getConnection();
    }

    public boolean inserirDados(Usuario usuario) {
        boolean flag = false;
        try {
            String sql = "INSERT INTO usuarios VALUES (,?, ?, ?, ?);";

            PreparedStatement pstm = this.connection.prepareStatement(sql);
            pstm.setString(1, usuario.getUsuario());
            pstm.setString(2, usuario.getSenha());
            pstm.setString(3, usuario.getNome());
            pstm.setString(4, usuario.getNivel());
            ResultSet rs = pstm.executeQuery();
            flag = rs.next();

        } catch (SQLException eAuth) {
            System.out.println("Houve erro na autenticação do usuario");
            eAuth.printStackTrace();
        }

        return flag;
    }
}
